package com.stt.design.service;

import com.stt.design.manager.TaskManager;
import com.stt.design.model.DesignTask;
import com.stt.design.model.TaskSaveVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 设计模式任务业务类
 */
@Service
public class DesignTaskService {

    private final TaskManager taskManager = TaskManager.getInstance();
    /**
     * 添加任务
     */
    public void addTask(TaskSaveVO taskSaveVO) {

        DesignTask task = new DesignTask.Builder(taskSaveVO.getTaskName())
                .addSubtask(taskSaveVO.getSubTask())
                .setPriority(taskSaveVO.getLevel())
                .setTag(taskSaveVO.getTag())
                .build();
        taskManager.addTask(task);
    }

    /**
     * 获取优先级大于等于minPriority的任务列表
     */
    public void getTasks(int minPriority) {
        Iterator<DesignTask> designTaskIterator = taskManager.priorityIterator(minPriority);
        while (designTaskIterator.hasNext()) {
            DesignTask task = designTaskIterator.next();
            System.out.println("- " + task.getTitle()
                    + " [优先级：" + task.getPriority() + "]");
        }
    }

    /**
     * 获取任务数量
     */
    public int getSize() {
        return taskManager.getSize();
    }
}
